package com.tanhua.server.controller;

import com.tanhua.model.vo.CommentVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.VideoVo;
import com.tanhua.server.service.SmallVideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 小视频控制层管理
 */
@RestController
@RequestMapping("/smallVideos")
public class SmallVideoController {

    @Autowired
    private SmallVideoService smallVideoService;

    /**
     * 视频发布
     * @param videoThumbnail 视频封面文件
     * @param videoFile 视频文件
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity publish(MultipartFile videoThumbnail,MultipartFile videoFile){
        smallVideoService.publish(videoThumbnail,videoFile);
        return ResponseEntity.ok(null);
    }



    /**
     * 视频列表分页查询（推荐系统视频数据==>视频表分页查询）
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity findPage(@RequestParam(value = "page",defaultValue = "1") Long page,@RequestParam(value = "pagesize",defaultValue = "10") Long pagesize){
        PageResult<VideoVo> pageResult =  smallVideoService.findPage(page,pagesize);
        return ResponseEntity.ok(pageResult);
    }

    /**
     * 小视频-点赞
     */
    @RequestMapping(value = "/{vid}/like",method = RequestMethod.POST)
    public ResponseEntity like(@PathVariable("vid") String  id){

       Integer count = smallVideoService.like(id);

        return ResponseEntity.ok(count);
    }


    /**
     * 视频-点赞取消
     */
    @RequestMapping(value = "/{Id}/dislike",method = RequestMethod.POST)
    public ResponseEntity dislike(@PathVariable("Id") String  Id){

        Integer count = smallVideoService.dislike(Id);

        return ResponseEntity.ok(count);
    }

    /**
     * 小视频评论发布
     * @param id
     * @param
     * @return
     */
    @PostMapping("/{id}/comments")
    public ResponseEntity comments(@PathVariable("id")String id,@RequestBody Map<String,String>  param){
        String comment = param.get("comment");
        smallVideoService.comments(id,comment);
        return ResponseEntity.ok(null);
    }


    /**
     * 小视频评论列表查询
     */
    @RequestMapping(value = "/{id}/comments",method = RequestMethod.GET)
    public ResponseEntity vedioList(@RequestParam(value = "page", defaultValue = "1") Long page,
                                       @RequestParam(value = "pageSize", defaultValue = "10")Long pageSize,
                                       @PathVariable("id") String id){
        PageResult<CommentVo> commentVoPageResult = smallVideoService.videoList(page,pageSize,id);
        return ResponseEntity.ok(commentVoPageResult);
    }


    /**
     * 小视频评论-点赞
     */
    @RequestMapping(value = "/comments/{id}/like",method = RequestMethod.POST)
    public ResponseEntity commentsLike(@PathVariable("id") String  id){

        Integer count = smallVideoService.commentsLike(id);

        return ResponseEntity.ok(count);
    }


    /**
     * 小视频评论-点赞取消
     */
    @RequestMapping(value = "/comments/{id}/dislike",method = RequestMethod.POST)
    public ResponseEntity commentsDislike(@PathVariable("id") String  Id){

        Integer count = smallVideoService.commentsDislike(Id);

        return ResponseEntity.ok(count);
    }

    /**
     * 小视频-添加关注
     */
    @RequestMapping(value = "/{uid}/userFocus",method = RequestMethod.POST)
    public ResponseEntity addFocus(@PathVariable("uid") Long uid){
        Boolean isLike =true;
        smallVideoService.addFocus(uid,isLike);

        return ResponseEntity.ok(null);
    }

    /**
     * 小视频-撤销关注
     */
    @RequestMapping(value = "/{uid}/userUnFocus",method = RequestMethod.POST)
    public ResponseEntity userUnFocus(@PathVariable("uid") Long uid){
        Boolean isLike =false;
        smallVideoService.addFocus(uid,isLike);

        return ResponseEntity.ok(null);
    }
}
